package cn.com.controller.manageController;


import cn.com.Enum.UserAuth;
import cn.com.annotation.Auth;
import cn.com.constant.Code;
import cn.com.db.model.Seller;
import cn.com.db.service.SellerService;
import cn.com.util.DataResult;
import cn.com.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Auth(UserAuth.ADMIN)
@RestController
@RequestMapping("/back/seller")
public class SellerManageController {

    @Autowired
    SellerService sellerService;

    @RequestMapping(method = RequestMethod.POST)
    public String getSeller(@RequestParam("page")Integer page,
                            @RequestParam("count")Integer count){
        DataResult dataResult=new DataResult();
        dataResult.setData(sellerService.getSeller(page,count));
        dataResult.setTotal(sellerService.countSeller());
        dataResult.setCode(Code.SUCCESS);
        dataResult.setMessage("返回成功");
        return JsonUtil.toJsonString(dataResult);
    }

    @RequestMapping(value = "/verify",method = RequestMethod.POST)
    public String verifySeller(HttpServletRequest request,
                               @RequestParam("sellerAuthing")String sellerAuthing){
        DataResult dataResult=new DataResult();
        Seller seller= sellerService.getSellerByAuthingId(sellerAuthing);
        if (seller==null){
            dataResult.setCode(Code.NOT_FOUND);
            dataResult.setMessage("商家不存在");
            return JsonUtil.toJsonString(dataResult);
        }
        seller.setVerify(true);
        seller.setAble(true);
        sellerService.updateSeller(seller);
        dataResult.setCode(Code.SUCCESS);
        dataResult.setMessage("返回成功");
        return JsonUtil.toJsonString(dataResult);
    }


}
